package com.itaming.lycheeframework.validation.validators;

import com.itaming.lycheeframework.support.utils.RegexUtil;
import com.itaming.lycheeframework.support.utils.StringUtil;
import com.itaming.lycheeframework.validation.constraints.ChineseIdCard;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

/**
 * 大陆身份证号码校验类
 *
 * @author A.Ming
 */
public class ChineseIdCardValidator implements ConstraintValidator<ChineseIdCard, String> {

    @Override
    public boolean isValid(String fieldValue, ConstraintValidatorContext constraintValidatorContext) {
        // 空值用 NotNull 和 NotEmpty 校验
        return StringUtil.isEmpty(fieldValue) || RegexUtil.isChineseIdCard(fieldValue);
    }

}
